﻿$(document).ready(function () {
    //$("#container").height(window.top.art.dialog.get("search").iframe.height);

    //获取父页面中被选中的车辆
    $("#vehicles").val($(window.top.document).find("#vehicles").val());

    $("#searchForm").submit(function () {
        $("#errorPic").hide();
        $("#tablelist").children(":visible").remove();
        return true;
    });

    $("#searchForm").submit();
});

function loadFailed() {
    $("#errorPic").show();
}

//ajax表单加载完毕后的事件，为页码添加事件
function loadComplete() {
    registertableevent();

    $("#pagerDiv a").click(function () {
        //给searchform添加pageIndex参数
        if ($(this).attr("disabled") == "disabled") {
            return false;
        }
        $("#searchForm #pageIndex").val($(this).attr("value"));

        $("#searchForm").submit();
    });


    $("#pagerDiv select").change(function () {
        $("#searchForm #pageIndex").val($(this).attr("value"));

        $("#searchForm").submit();
    });
}

//日里程统计，ajax表单加载完毕后，为表格行注册点击事件，点击表格行显示里程明细
function loadCompleteAndClick() {
    loadComplete();

    $("#tablelist .tablelist tbody tr").click(function () {
        var url = "/MileageStatistics/MileageDetail?sim=" + $(this).attr("id") + "&startDate=" + $("#startDate").val() + "&endDate=" + $("#endDate").val();
        var selector = "#secondtablelist";

        ajaxLoad(selector,
            url
            //url,
            //function () {
            //    var h = ($("#mileagedetail").parent().eq(0).height() - 2) + "px";
            //    var w = ($("#mileagedetail").parent().eq(0).width()) + "px";
            //    $("#mileagedetail").chromatable({
            //        height: h,
            //        width: w,
            //        scrolling: "yes"
            //    });
            //});
            );
    });

    $("#tablelist .tablelist tbody tr:nth-child(1)").trigger("click");
}


//日里程统计，ajax表单加载完毕后，为表格行注册点击事件，点击表格行显示里程明细
function loadCompleteAndClick1() {
    loadComplete();
    if ($("#tablelist .tablelist").width() < $("#tablelist").width()) {
        $("#tablelist .tablelist").css("width","100%");
    }
    $("#tablelist .tablelist tbody tr").click(function () {
        var url = "/WarningDetail/Detail?sim=" + $(this).attr("id") + "&startTime=" + encodeURI($("#startTime").val()) + "&endTime=" + encodeURI($("#endTime").val()) + "&warningTypes=" + $("#warningTypes").val();
        //var url = "/WarningDetail/Detail?sim=" + $(this).attr("id") + "&startTime=2014-07-01&endTime=2014-07-0800&warningTypes=0;1";
        var selector = "#secondtablelist";

        ajaxLoad(selector,
            url
            //url,
            //function () {
            //    var h = ($("#mileagedetail").parent().eq(0).height() - 2) + "px";
            //    var w = ($("#mileagedetail").parent().eq(0).width()) + "px";
            //    $("#mileagedetail").chromatable({
            //        height: h,
            //        width: w,
            //        scrolling: "yes"
            //    });
            //});
            );
    });

    $("#tablelist .tablelist tbody tr:nth-child(1)").trigger("click");
}